package com.volunteer.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.volunteer.entity.Comment;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * 评论Mapper接口
 */
@Mapper
public interface CommentMapper extends BaseMapper<Comment> {

    /**
     * 增加评论点赞数
     * @param commentId 评论ID
     * @return 影响行数
     */
    @Update("UPDATE t_comment SET likes = likes + 1 WHERE id = #{commentId}")
    int incrementLikes(@Param("commentId") Long commentId);

    /**
     * 减少评论点赞数
     * @param commentId 评论ID
     * @return 影响行数
     */
    @Update("UPDATE t_comment SET likes = likes - 1 WHERE id = #{commentId} AND likes > 0")
    int decrementLikes(@Param("commentId") Long commentId);
}
